-- Viral Resistance - T-Engine 4 Module
-- Copyright (C) 2010 Mikolai Fajer
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Mikolai Fajer "yufra"
-- mfajer@gmail.com

newChat{ id="welcome",
	text = [[#LIGHT_GREEN#The chief of virology stands in the doorway, frantically waving you over. #WHITE#"Hurry, we don't have much time!"]],
	answers = {
		{'"What is wrong?"', jump="accept",
			cond=function(npc, player) return not player:isQuestStatus("code_green", engine.Quest.PENDING, "anti-virals") end,
			action=function(npc, player) return player:setQuestStatus("code_green", engine.Quest.COMPLETED, "report") end},
		{'"Here is the anti-viral!"',
			jump="access",
			cond=function(npc, player) return player:isQuestStatus("code_green", engine.Quest.PENDING, "anti-virals") and player:hasQuest("code_green"):can_offer(player) end,
			action=function(npc, player, dialog) player:hasQuest("code_green"):collect_antiviral(player, dialog) end
		},
		{'"I\'ll be right back!"',},
	}
}

newChat{ id="accept",
	text = [["Private Andrews was admitted this morning after possible exposure to a biological weapon."]],
	answers = {
		{'"A what?!"', jump="surprise"},
		{'"What is his status?"', jump="status"},
	}
}
newChat{ id="surprise",
	text = [["Pull it together doctor, we have a job to do."]],
	answers = {
		{'"Yes sir!"', jump="status"},
	}
}
newChat{ id="status",
	text = [[#LIGHT_GREEN#The chief continues, #WHITE#"Blood draws an hour ago showed a steady increase in the patient's viral load, and his body appears to be shutting down now.  We need to administer another dose of anti-virals right away.  Grab some from the nurse's station behind you and report back here."]],
	answers = {
		{'"I have the anti-viral right here!"',
			jump="access",
			cond=function(npc, player) return player:hasQuest("code_green"):can_offer(player) end,
			action=function(npc, player, dialog) player:hasQuest("code_green"):collect_antiviral(player, dialog) end
		},
		{'"I\'ll be right back!"', action=function(npc, player) player:setQuestStatus("code_green", engine.Quest.PENDING, "anti-virals") end},
	}
}
newChat{ id="access",
	text = [[#LIGHT_GREEN#The chief holds up the vial and inspects the label.  He nods and attaches the vial to a syringe. #WHITE#"Great, let us get in there then."]],
	answers = {
		{'Follow the chief into the room.', jump="administer", action=function(npc, player)
			player:setQuestStatus("code_green", engine.Quest.COMPLETED, "anti-virals")
			npc:move(1, 1, true)
			player:move(1, 2, true)
		end},
	}
}

newChat{ id="administer",
	text = [["Hold him down while I administer the anti-viral."  #LIGHT_GREEN#The chief leans over the bed as you hold the patient down and is just about to plunge the syringe into a vein when the patient begins to thrash violently beneath you.  #WHITE#"Wait, what is happening to him?!"]],
	answers = {
		{"#LIGHT_BLUE#Let go of the patient", jump="zombies", action=function(npc, player)
			-- Activate the zombies!
			local patients = {}
			for i,v in pairs(game.level.entities) do
				if v.name == "patient" then
					table.insert(patients, v)
				end
			end
			for i,patient in ipairs(patients) do
				-- Closest patient should instantly spawn
				local dist = core.fov.distance(player.x, player.y, patient.x, patient.y)
				local offset = dist < 3 and 0 or dist * 2
				patient:takeVloadHit(100 - offset, {name="Viral Contamination"})
			end
			-- And change the actor resolver
			game.zone.levels[2].generator.actor = {
				class = "engine.generator.actor.Random",
				nb_npc={30, 50},
				post_generation = function(m)
					if m.type == "human" and rng.percent(75) then
						m:die()
					elseif m.type == "zombie" and rng.percent(25) then
						m:die()
					end
				end,
			}
		end},
	}
}

newChat{ id="zombies",
	text = [[#LIGHT_GREEN#You and the chief of medicine watch in horror as the patient's eyes bulge and fill with blood.  #WHITE#"Something is wrong, initiate the lockdown!  The button is by the ward entrance... HURRY!"  #LIGHT_GREEN#The chief then throws himself on top of the patient, trying to pin him to the bed.]],
	answers = {
		{'"Yes sir!"', action=function(npc, player)
			player:setQuestStatus("code_green", engine.Quest.COMPLETED, "administer")
			player:setQuestStatus("code_green", engine.Quest.PENDING, "lockdown")
			player:newEffect{name="OUTER_LOCKDOWN_COUNTDOWN", desc=[[]], type="countdown", 
				on_lose = function(self, err)
					if player:isQuestStatus("code_green", engine.Quest.COMPLETED, "lockdown") then return end
					local chat = engine.Chat.new("lockdown", {name="Surveillance"}, player)
					chat:invoke("auto_lockdown")
				end,
			}
			player:setEffect(player.EFF_OUTER_LOCKDOWN_COUNTDOWN, 60, {})
		end},
	}
}
return "welcome"
